/*
 * TowerGreenOne.java
 *
 * Created on November 24, 2007, 3:34 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package hextd.tower;

import hextd.hex.Hex;
import hextd.creep.Creep;
import hextd.core.Context;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;

/**
 *
 * @author hylke
 */
public class TowerGreenOne extends TowerBase {

    public static int price = 100;
    public static int damage = 10;
    public static float range = 4f;
    private Creep fireAt = null;
    private Creep.COLOR damageColor = Creep.COLOR.GREEN;

    /** Creates a new instance of TowerGreenOne */
    public TowerGreenOne(Context context, Hex hex, int owner, int activateTick) {
        super(TowerFactory.type.greenOne, price, damage, range, owner, activateTick);
        this.lineColor = Color.GREEN;
        hexInfluence = 1;
        this.doInit(context, hex);
    }

    @Override
    public void runTick(int gameTime) {
        if (!this.lock) {
            this.fireAt = null;
        }
        Creep enemy = this.findEnemy(this.fireAt, false);

        this.fireAt = enemy;
        if (enemy != null) {
            enemy.doDamage(this.getOwner(), this.damageCurrent, this.damageColor);
        }
    }

    @Override
    public String getStatusString() {
        String retString = "";
        retString += "<h1>Green Tower 1</h1>" +
                "<p>" +
                "<b>Level:</b> " + (1 + this.level) + "<br>\n" +
                "<b>Damage:</b> " + this.damageText + "<br>\n" +
                "<b>Range:</b> " + this.rangeText + "<br>" +
                "</p>\n";
        return retString;
    }

    @Override
    public String getInfoString() {
        String retString = "";
        retString += "<h1>Green Tower 1</h1>" +
                "<p>" +
                "Basic tower with one weak laser. Strong against green enemies, very weak against red enemies.</p>" +
                "<p>" +
                "<b>Price:</b> " + TowerGreenOne.price + "<br>" +
                "<b>Damage:</b> " + this.damageCurrent + "<br>" +
                "<b>Range:</b> " + TowerGreenOne.form.format(rangeCurrent) + "<br>" +
                "<b>Refire rate:</b> 20/s" +
                "</p>";
        return retString;
    }

    @Override
    protected void generateShapes() {
        float width = hexPaintWidth;
        int shapeCount = 5;
        this.shapes = new Shape[shapeCount];
        this.shapes[0] = new Ellipse2D.Float(-0.4f * this.paintScale, -0.4f * this.paintScale, 0.8f * this.paintScale, 0.8f * this.paintScale);
        this.shapes[1] = new Line2D.Float(0, 0.4f * paintScale, 0, paintScale);
        this.shapes[2] = new Line2D.Float(-0.4f * width, -0.5f * 0.4f * paintScale, -width, -0.5f * paintScale);
        this.shapes[3] = new Line2D.Float(0.4f * width, -0.5f * 0.4f * paintScale, width, -0.5f * paintScale);
        this.shapes[4] = new Ellipse2D.Float(-1.0f * strokeScale, -1.0f * strokeScale, 2.0f * strokeScale, 2.0f * strokeScale);

        this.shapeAction = new int[shapeCount];
        this.shapeAction[0] = 1;
        this.shapeAction[1] = 1;
        this.shapeAction[2] = 1;
        this.shapeAction[3] = 1;
        this.shapeAction[4] = 1;

        this.shapeColor = new Color[shapeCount];
        this.shapeColor[0] = this.lineColor;
        this.shapeColor[1] = this.lineColor;
        this.shapeColor[2] = this.lineColor;
        this.shapeColor[3] = this.lineColor;
        this.shapeColor[4] = this.lineColor;

        this.strokes = new Stroke[shapeCount];
        this.strokes[0] = new BasicStroke(2.0f * strokeScale, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
        this.strokes[1] = this.strokes[0];
        this.strokes[2] = this.strokes[0];
        this.strokes[3] = this.strokes[0];
        this.strokes[4] = this.strokes[0];
    }

    @Override
    public void paintEffects(Graphics2D g2, int gameTime) {
        Stroke defaultStroke = g2.getStroke();

        Creep t = this.fireAt;
        if (t != null) {
            g2.setColor(this.lineColor);
            g2.draw(new Line2D.Float(this.xPaint,
                    this.yPaint,
                    t.getPaintX() + ((float) (Math.random() - 0.5) * this.paintScale / 10f),
                    t.getPaintY() + ((float) (Math.random() - 0.5) * this.paintScale / 10f)));
        }

        g2.setStroke(defaultStroke);
    }
}
